DesertPillar.hlsl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef LINE_KIT_DEMOS_DESERT_PILLAR_INCLUDED
  2. #define LINE_KIT_DEMOS_DESERT_PILLAR_INCLUDED
  3. #include "Noise/ClassicNoise3D.hlsl"
  4. float Hash(float x) {
  5. float p = 1;
  6. #if defined(_TYPE_A)
  7. p = 43.5453;
  8. #endif
  9. return frac(sin(x) * p) * 10;
  10. }
  11. void PillarColor_float(float2 UV, float3 ObjectPositionWS, float3 ObjectScale, float3 PositionWS, float3 NormalWS,
  12. float3 LightDirection, float LightAttenuation, out float3 Color) {
  13. float noise = 0;
  14. const float hash = Hash(ObjectPositionWS.x + ObjectPositionWS.y + ObjectPositionWS.z);
  15. const float3 p = (PositionWS + hash) / ObjectScale * _ScaleFactor;
  16. #if defined(_TYPE_A)
  17. noise += ClassicNoise(p * _NoiseScale1 * 1.0) * 1.0;
  18. noise += ClassicNoise(p * _NoiseScale2 * 2.0) * 0.5;
  19. #elif defined(_TYPE_B)
  20. noise = ClassicNoise(p.y * 2 + atan(p.x / p.z) * 50 * _NoiseScale1);
  21. #elif defined(_TYPE_C)
  22. noise = ClassicNoise(p.y * _NoiseScale1.x +
  23. ClassicNoise((UV.x * _NoiseScale1.y *
  24. sin(p.y * _NoiseScale2.z)) * _NoiseScale2.x) *
  25. _NoiseScale2.y);
  26. #endif
  27. const float section23 = step(_Distribution.x, noise);
  28. const float section3 = step(_Distribution.y, noise);
  29. Color = lerp(_Color1, lerp(_Color2, _Color3, section3), section23).rgb;
  30. // Apply _ColorTop to the faces pointing up.
  31. const float3 up = float3(0, 1, 0);
  32. const float isTop = step(1 - _TopSize, dot(up, NormalWS));
  33. Color = lerp(Color, _ColorTop, isTop);
  34. const float shadowStrength = _ShadowStrength;
  35. const float shadowSize = _ShadowSize;
  36. const float shadowSharpness = _ShadowSharpness;
  37. const float3 shadowDirection = normalize(-LightDirection + NormalWS * (1 - shadowSize));
  38. float shadow = saturate(dot(shadowDirection, NormalWS));
  39. const float shadowBand = (1.0 - shadowSharpness) * 0.5;
  40. shadow = smoothstep(shadowSize - shadowBand, shadowSize + shadowBand, shadow);
  41. shadow = lerp(1, shadow, shadowStrength);
  42. shadow = min(shadow, LightAttenuation);
  43. shadow = 1 - shadow;
  44. // Give shadow tint of _ShadowTint and blend it with the color.
  45. Color = lerp(Color, _ShadowTint.rgb, shadow * _ShadowTint.a);
  46. }
  47. #endif // LINE_KIT_DEMOS_DESERT_PILLAR_INCLUDED